package com.lxf.clouduser.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * @author 罗兴发
 * @data 2025/5/12 9:27
 * @description：线程池配置
 */
@Configuration
public class ThreadPoolConfig {

    @Bean
    public Executor taskExecutor(){
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        //设置线程池参数
        taskExecutor.setCorePoolSize(5);//核心线程数量
        taskExecutor.setMaxPoolSize(10);//最大线程数量
        taskExecutor.setQueueCapacity(25);//任务队列容量
        taskExecutor.setKeepAliveSeconds(2000);//存活时间
        taskExecutor.setThreadNamePrefix("Async-TaskExecutor");//前缀
        return taskExecutor;
    }
}
